package com.sk.leetcode.arithmetic.test1_10;


/**
 * 给定一个 32 位有符号整数，将整数中的数字进行反转。
 */
public class Test7 {
    public static void main(String[] args) {
        int n = reverse(-1233345566);
        System.out.println(n);
    }

    public static int reverse(int x) {
        String str = Integer.toString(x);
        String[] strs = str.split("");
        int num = 0;
        if("-".equals(strs[0])) {
            num = 1;
        }
        boolean b=true;
        for (int i = num, j = (strs.length - 1);b; i++, j--) {
            if(i >= j) {
                b=false;
                continue;
            }
            String l = strs[j];
            strs[j] = strs[i];
            strs[i] = l;
        }
        String string = String.join("",strs);

        long n = Long.parseLong(string);
        if(n != (int)n){
            return 0;
        }
        return  (int)n;
    }
}
